package org.devocean.groupbuying.service.impl;

import java.util.List;

import org.devocean.groupbuying.dao.PromotionDAO;
import org.devocean.groupbuying.domain.Promotion;
import org.devocean.groupbuying.service.PromotionService;
import org.devocean.groupbuying.service.ExploredService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PromotionServiceImpl implements PromotionService {

	@Autowired
	private PromotionDAO promotionDAO;

//	@Autowired
//	private ExploredService exploredService;

	@Transactional(readOnly = true)
	public Promotion getPromotionById(Integer promotionID) {

		return promotionDAO.findPromotionById(promotionID);
	}

	@Transactional
	public Promotion addOrUpdatePromotion(Promotion promotion) {

		final Promotion newPromotion;

		if (promotion.getPromotionID() == null) {
			newPromotion = promotionDAO.savePromotion(promotion);
		} else {
			newPromotion = promotionDAO.updatePromotion(promotion);
		}

//		exploredService.addOrUpdateExplored(newPromotion);
		return newPromotion;
	}

	@Transactional
	public void removePromotion(Integer promotionID) {
		promotionDAO.deletePromotion(promotionID);
	}

	public long countPromotions() {

		return promotionDAO.countPromotion();
	}

	@Transactional
	public List<Promotion> getAllPromotions() {
		return promotionDAO.findAllPromotions();
	}


	public List<Promotion> getPromotionsByProduct(Integer productID) {
		return promotionDAO.findPromotionsByProduct(productID);
	}

	public List<Promotion> getPromotionsByPlan(Integer planID) {
		// TODO Auto-generated method stub
		return promotionDAO.getPromotionsByPlan(planID);
	}

}
